<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最后一个单词的长度</title>
</head>
<body>
  <script>
    function fn(s) {
      // trim() 删除字符串的头尾空白符，空白符
      s = s.trim();
      var count = 0;
      var len = s.length;
      for (var i = len - 1; i >= 0; i--) {
        if (s.charAt(i) == ' ') break;
        count++;
      }
      return count;
    }
    console.log(fn('   fly me   to   the moon  '))
  </script>
</body>
</html>